﻿<%@ Page Title="Wild2" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Wild2.Models.Pages.User.Top>" %>
<asp:Content ID="TitleContent" ContentPlaceHolderID="TitleContent" runat="server">
    <%= Resources.Home.Title %>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="HeaderBlockContent" runat="server">
<%--Keywords--%>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="HeaderContent" runat="server">
    <%  String version = "pda"; if (Session[Wild2.Models.Constants.SessionConstants.VERSION] != null) version = Session[Wild2.Models.Constants.SessionConstants.VERSION].ToString(); %>
    <% Html.RenderPartial("~/Views/Shared/" + version + "/Header.ascx", "Пользователи сайта"); %>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%  String version = "pda"; if (Session[Wild2.Models.Constants.SessionConstants.VERSION] != null) version = Session[Wild2.Models.Constants.SessionConstants.VERSION].ToString(); %>
    <% if (!String.IsNullOrEmpty(Model.infoMessage))
       {
           Html.RenderPartial("~/Views/Shared/" + version + "/InfoBox.ascx", Model.infoMessage);
       } %>
       <div class="container">
        <% Html.RenderPartial("~/Views/Shared/" + version + "/Panel.ascx", "Нас " + Model.CountUsers + " пользовател(ь|ей)"); %>
        <% 
            foreach (var user in Model.UsersData)
            {
                String online = "";
                int onlinetime = 15;
                if (ConfigurationManager.AppSettings["onlinetime"] != null) { onlinetime = Int32.Parse(ConfigurationManager.AppSettings["onlinetime"]); }
                if (user.LastOnlineDate.AddMinutes(onlinetime).CompareTo(DateTime.Now) > 0) online = "online";

                int age = 0;
                if (user.Birth.HasValue)
                {
                    DateTime birth = user.Birth.Value;
                    age = DateTime.Now.Year - birth.Year;
                    if ((DateTime.Now.Month < birth.Month) || ((DateTime.Now.Month == birth.Month) && (DateTime.Now.Day < birth.Day))) age--;
                }
                
                Html.RenderPartial("~/Views/Shared/" + version + "/Element.ascx", Html.ActionLink(user.Nick, "Index", new { id = user.ID }, new { @class = online }) +
                                                                                  " " + ((user.isMale.HasValue) ? ((user.isMale.Value) ? ("М") : ("Ж")) : ("")) +
                                                                                  ((user.Birth.HasValue) ? (" " + age) : (""))
                                                                                  );
            }
        %>
        <%
            String naviblock = "";
            if (Model.CountUsers > Model.ElOnPage)
            {
                if (Model.CurrentPage > 1)
                {
                    naviblock += Html.ActionLink("пред.", "Top", new { p = Model.CurrentPage - 1 }).ToString() + " ";
                }
                if (Model.CurrentPage < Model.LastPage)
                {
                    naviblock += Html.ActionLink("след.", "Top", new { p = Model.CurrentPage + 1 }).ToString() + " ";
                }
                naviblock += "<br />";

                if (Model.CurrentPage > 1) { naviblock += Html.ActionLink("1", "Top", new { p = 1 }).ToString() + " "; }

                if (Model.CurrentPage > 5) naviblock += ".. ";

                if ((Model.CurrentPage - 2) > 1) { naviblock += Html.ActionLink((Model.CurrentPage - 2).ToString(), "Top", new { p = Model.CurrentPage - 2 }).ToString() + " "; }

                if ((Model.CurrentPage <= 3) || (Model.CurrentPage >= Model.LastPage - 2)) if ((Model.CurrentPage - 1) > 1) { naviblock += Html.ActionLink((Model.CurrentPage - 1).ToString(), "Top", new { p = Model.CurrentPage - 1 }).ToString() + " "; }

                naviblock += Model.CurrentPage + " ";

                if ((Model.CurrentPage <= 3) || (Model.CurrentPage >= Model.LastPage - 2)) if ((Model.CurrentPage + 1) < Model.LastPage) { naviblock += Html.ActionLink((Model.CurrentPage + 1).ToString(), "Top", new { p = Model.CurrentPage + 1 }).ToString() + " "; }

                if ((Model.CurrentPage + 2) < Model.LastPage) { naviblock += Html.ActionLink((Model.CurrentPage + 2).ToString(), "Top", new { p = Model.CurrentPage + 2 }).ToString() + " "; }

                if (Model.CurrentPage < Model.LastPage - 4) naviblock += ".. ";

                if (Model.CurrentPage < Model.LastPage) { naviblock += Html.ActionLink(Model.LastPage.ToString(), "Top", new { p = Model.LastPage }).ToString(); }

                Html.RenderPartial("~/Views/Shared/" + version + "/Panel.ascx", "Страницы: <br />" + naviblock);
            }
            %>
            <%
                Html.BeginForm();
                Html.RenderPartial("~/Views/Shared/" + version + "/Panel.ascx", Html.TextBox("usernick", "", new { style = "width:10em" }) + " <input style=\"background-color: #7394BC; border-top: 1px solid #7E8FA9; border-left: 1px solid #7E8FA9; border-bottom: 1px solid #4C6F97; border-right: 1px solid #4C6F97; color: #FFFFFF\" type=\"submit\" value=\"Поиск\" />");
                Html.EndForm();
            %>
        </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="FooterContent" runat="server">
    <%  String version = "pda"; if (Session[Wild2.Models.Constants.SessionConstants.VERSION] != null) version = Session[Wild2.Models.Constants.SessionConstants.VERSION].ToString(); %>
    <% Html.RenderPartial("~/Views/Shared/" + version + "/Footer.ascx");
        %>
</asp:Content>